package com.sapient.DAO;

import java.sql.*;

import javax.servlet.RequestDispatcher;

import com.sapient.Config;

public class LoginDAO {

	private String url = "jdbc:oracle:thin:@10.207.60.85:1521/XE";
	private String username = "surv";
	private String password = "surv";
	Connection conn;
	Statement st;
	String pass=null;

	public void getConnection(){
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");

			conn= DriverManager.getConnection(url, username, password);

			st=conn.createStatement();
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}




	public String userValidate(String user) throws SQLException

	{

		getConnection();
		String query= "Select UserName,Password from UserTable where UserName='"+user+"'";
		ResultSet rs= st.executeQuery(query);
		if(rs.next())
		{
			pass=rs.getString("Password");
			return pass;
		}

		else
		{
			return null;

		}





	}

	public String getUserRole(String user) {
		getConnection();
		String query="Select UserRole from UserTable where UserName='"+user+"'";
		String role="";
		ResultSet rs = null;
		try {
			rs = st.executeQuery(query);
			while(rs.next())
			{
				role=rs.getString("UserRole");

			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(role);

		return role;
	}

}

